<template>
  <div class="ChangePassword">
    <FormPanel ref="FormPanel" :cols="1" :list="formList" formType="edit" :isSubmitBtn="false" :labelWidth="300" />
    <div style="margin-left: 600px;margin-top: 30px;">
      <el-button ref="save" type="primary" @click="save">保存</el-button>
      <el-button ref="register" type="primary" @click="register"> 注册</el-button>
    </div>
  </div>
</template>

<script>
import { getRegistrationInfo, saveRegistrationInfo, doRegistrationOpr } from '@/api/repair/electronicArchives';
import { notifyAction } from '@/utils';
export default {
  name: 'companyRegistration',
  data() {
    return {
      formList: this.createFormList()
    };
  },
  created() {
    this.getRegistrationInfo();
  },
  methods: {
    // 请求数据
    async getRegistrationInfo() {
      const res = await getRegistrationInfo();
      if (res.resultCode === 200) {
        if (res.data[0].UNIQUELY_IDENTIFIES != '' && res.data[0].UNIQUELY_IDENTIFIES != null) {
          this.formList[0].disabled = true;
          this.formList[1].disabled = true;
          this.formList[2].disabled = true;
          this.formList[3].disabled = true;
          this.$refs.save.disabled = true;
          this.$refs.register.disabled = true;
        }
        this.formList[0].initialValue = res.data[0].REPAIR_ENTERPRISE_NAME;
        this.formList[1].initialValue = res.data[0].REPAIR_ENTERPRISE_PWD;
        this.formList[2].initialValue = res.data[0].BUSINESS_LICENSE;
        this.formList[3].initialValue = res.data[0].REGION_CODE;
        this.formList[4].initialValue = res.data[0].UNIQUELY_IDENTIFIES;
      }
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '维修企业名称',
          fieldName: 'REPAIR_ENTERPRISE_NAME',
          initialValue: '',
          style: { width: '200px' },
          rules: [{ required: true, message: '请输入维修企业名称', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '维修企业密码',
          fieldName: 'REPAIR_ENTERPRISE_PWD',
          initialValue: '',
          style: { width: '200px' },
          rules: [{ required: true, message: '请输入维修企业密码', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '道路经营许可证号/机动车维修经营许可证号',
          fieldName: 'BUSINESS_LICENSE',
          initialValue: '',
          style: { width: '200px' },
          rules: [{ required: true, message: '请输入道路经营许可证号/机动车维修经营许可证号', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '维修企业注册区域编码',
          fieldName: 'REGION_CODE',
          initialValue: '',
          style: { width: '200px' },
          rules: [{ required: true, message: '请输入维修企业注册区域编码', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '维修企业唯一标识',
          disabled: true,
          fieldName: 'UNIQUELY_IDENTIFIES',
          style: { width: '200px' },
          descOptions: {
            style: {
              color: 'red',
              fontWeight: 'bold'
            },
            content: '需要点击注册后生成维修企业唯一标识'
          }
        }
      ];
    },
    // 进行保存按钮操作
    async save(val) {
      let data = this.$refs.FormPanel.SUBMIT_FORM();
      if (data) {
        const res = await saveRegistrationInfo(data);
        if (res.resultCode === 200) {
          notifyAction('企业信息保存成功！', 'success');
        }
      }
    },
    // 进行注册按钮操作
    async register(val) {
      let data = this.$refs.FormPanel.SUBMIT_FORM();
      if (data) {
        const res = await doRegistrationOpr(data);
        if (res.resultCode === 200) {
          this.getRegistrationInfo();
          notifyAction('企业信息注册成功！', 'success');
        }
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
